﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_AgencyChildList : System.Web.UI.Page,HZ.MBSM.BLL.IPageDescribe 
{
    Int64 AccountId;
    protected void Page_Load(object sender, EventArgs e)
    {
        string strBidY="", strBidN="", strSql;
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {
                AccountId = SysFun.ToLong(_Account.AccountId);

                if (!IsPostBack)
                {
                    lstType.Dispose();
                    lstType.Items.Add("全部");
                    lstType.Items.Add("基本库商品审核");
                    lstType.Items.Add("企业审核");
                    lstType.Items.Add("投标商品审核");
                    lstType.Items.Add("招标目录维护");
                    lstType.Items.Add("中药专家");
                    lstType.Items.Add("西药专家");
                    lstType.Items.Add("中药企业");
                    lstType.Items.Add("西药企业");
                    lstType.Items.Add("数据处理");
                    lstType.Items.Add("标书发放");
                    lstType.Items.Add("配送审核");
                    lstType.Items.Add("全能（产品、企业）");
                    lstType.Items.Add("各部门用户");
                }
                if (Request.Form["btnSubmit"] == "授权")
                {
                    foreach (string strId in SysFun.ToTrim(Request.Form["AccountId"]).Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        if (SysFun.ToInt(Request.Form["radBid" + strId]) == 1)
                            strBidY = strBidY + strId + ",";
                        else
                            strBidN = strBidN + strId + ",";
                    }
                    Db db = new Db();
                    //分别授权
                    if (strBidN != "")
                    {
                        strBidN = strBidN.Substring(0, strBidN.Length - 1);
                        strSql = "update account set IsBid_Landing=0 WHERE AccountId in (" + strBidN + ") ";
                        db.Command(strSql);

                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "account", strSql, "../Agency/AgencyChildList.aspx");

                        //db.Close();
                    }
                    if (strBidY != "")
                    {
                        strBidY = strBidY.Substring(0, strBidY.Length - 1);
                        strSql = "update account set IsBid_Landing=1 WHERE AccountId in (" + strBidY + ") ";
                        db.Command(strSql);
                        //db.Close();
                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "account", strSql, "../Agency/AgencyChildList.aspx");

                    }
                    db.Close();
                    db = null;
                }

                showGridView();
            }
            else
            {
                Response.Write("<script language=JavaScript>alert('您还没有登录，暂时无权添加子用户！！！');</script>");
            }
        }
    }
    public void showGridView()
    {
        int i = 0;
        string strConditions;
        strConditions = "";
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "v_Account_AgencyChild ";
        dbPage.Key = "accountid";
        dbPage.Where = strConditions;
        dbPage.SelectField = "AccountId, AccountName,Pwd_Bid,case Type when '5' then '基本库商品审核' when '6' then '企业审核' when '7' then '投标商品审核' when '8' then '招标目录维护' when '9' then '中药专家'  when '10' then '西药专家' when '11' then '中药企业' when '12' then '西药企业' when '13' then '数据处理'  when '14' then '配送审核'  when '17' then '标书发放' end as type,UserName, Telephone,ZC,IsBid_Landing,UserCode";
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);
        dbPage.PageSize = 10;//Request.QueryString["PS"]);
        dbPage.OrderBy = "AccountName";
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' border='0' align='center' cellpadding='2' cellspacing='1' class='list'>");
        strHtml.Append("<tr>");
        strHtml.Append("<td class='table_title' nowrap>用户名称</td>");
        strHtml.Append("<td class='table_title' nowrap>用户编码</td>");
        strHtml.Append("<td class='table_title' nowrap>姓名</td>");
        strHtml.Append("<td class='table_title' nowrap>密码</td>");
        strHtml.Append("<td class='table_title' nowrap>权限</td>");
        strHtml.Append("<td class='table_title' nowrap>授权</td>");
        strHtml.Append("<td class='table_title' nowrap>修改</td>");
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        while (dr.Read())
        {
            if (i == 0)
            {
                strHtml.Append("<tr class='table_td'>");
                i++;
            }
            else
            {
                strHtml.Append("<tr class='table_td2'>");
                i--;
            }

            strHtml.Append("<td><input type='hidden' name='AccountId' value='" + SysFun.ToTrim(dr["accountid"]) + "'>" + dr["accountname"].ToString() + "</td>");
            strHtml.Append("<td>" + SysFun.ToTrim(dr["UserCode"]) + "</td>");
            strHtml.Append("<td>" + SysFun.ToTrim(dr["UserName"]) + "</td>");
         //   strHtml.Append("<td>" + SysFun.PasswordDecrypt(SysFun.ToTrim(dr["Pwd_Bid"])) + "</td>");
            strHtml.Append("<td>******</td>");
            strHtml.Append("<td>" + SysFun.ToTrim(dr["Type"]) + "</td>");
            strHtml.Append("<td>");
            if (SysFun.ToTrim(dr["isbid_landing"]) == "1")
            {
                strHtml.Append("<input type=radio name ='radBid" + dr["accountid"].ToString() + "' value='1' checked>是");
                strHtml.Append("<input type=radio name ='radBid" + dr["accountid"].ToString() + "' value='0'>否");
            }
            else
            {
                strHtml.Append("<input type=radio name ='radBid" + dr["accountid"].ToString() + "' value='1'>是");
                strHtml.Append("<input type=radio name ='radBid" + dr["accountid"].ToString() + "' value='0' checked>否");
            }
            strHtml.Append("</td>");
            strHtml.Append("<td><a target=_blank  href='AgencyChildUpdate.aspx?AccountId=" + dr["accountid"].ToString() + "'>修改</a></td>");
            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        Label1.Text = strHtml.ToString();
        //LabRowCount.Text = dbPage.RowCount.ToString();
        //LabPageCount.Text = dbPage.PageCount.ToString();
        //LabPageIndex.Text = dbPage.PageIndex.ToString();
        dr.Close();
        dbPage.Db.Close();
        db.Close();
        dr = null;
        db = null;

        this.DbPageFlip1.DbPage = dbPage;


    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp, AccountName, UserName, UserCode;
        AccountName = txtAccountName.Text.ToString().Trim(); 
        UserName = txtUserName.Text.ToString().Trim();
        UserCode = SysFun.ToTrim(txtUserCode.Text);
        strtemp = " AccountId_father='" + SysFun.ToTrim(AccountId) + "' and";
        switch (lstType.SelectedValue.ToString())
        {
            case "全部":
                break;
            case "基本库商品审核":
                strtemp = strtemp + " type=5 and";
                break;
            case "企业审核":
                strtemp = strtemp + " type=6 and";
                break;
            case "投标商品审核":
                strtemp = strtemp + " type=7 and";
                break;
            case "招标目录维护":
                strtemp = strtemp + " type=8 and";
                break;
            case "中药专家":
                strtemp = strtemp + " type=9 and";
                break;
            case "西药专家":
                strtemp = strtemp + " type=10 and";
                break;
            case "中药企业":
                strtemp = strtemp + " type=11 and";
                break;
            case "西药企业":
                strtemp = strtemp + " type=12 and";
                break;
            case "数据处理":
                strtemp = strtemp + " type=13 and";
                break;
            case "全能（产品、企业）":
                strtemp = strtemp + " type=16 and";
                break;
            case "标书发放":
                strtemp = strtemp + " type=17 and";
                break;
            case "配送审核":
                strtemp = strtemp + " type=14 and";
                break;
            case "各部门用户":
                strtemp = strtemp + " type=15 and";
                break;
        }
        if (UserCode != "")
        {
            strtemp = strtemp + " UserCode like '%" + UserCode + "%' and";
        }
        if (AccountName != "")
        {
            strtemp = strtemp + " AccountName like '%" + AccountName + "%' and";
        }
        if (UserName != "")
        {
            strtemp = strtemp + " UserName like '%" + UserName + "%' and";
        }
        if (strtemp != "")
        {
        strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }


    #region IPageDescribe 成员

    public string Name
    {
        get { return "子用户管理"; }
    }

    public string Describe
    {
        get { return "子用户管理"; }
    }

    public string ParentName
    {
        get { return "子用户管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
            return _AccountType;
        }
    }

    #endregion
}
